package com.fr.report.script.function;

import com.fr.base.core.DateUtils;
import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;
import java.util.Date;

public class DATEINYEAR extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if (paramArrayOfObject.length < 2)
      return Primitive.ERROR_NAME;
    Object localObject1 = paramArrayOfObject[0];
    Object localObject2 = paramArrayOfObject[1];
    if (!(localObject2 instanceof Number))
      return localObject1;
    int i = ((Number)localObject2).intValue();
    int j = -1;
    if (localObject1 instanceof Number)
      j = ((Number)localObject1).intValue() - 1900;
    else if (localObject1 != null)
      j = DateUtils.object2Date(localObject1, false).getYear();
    if (j == -1)
      j = new Date().getYear();
    return new Date(j, 0, i);
  }

  public Function.Type getType()
  {
    return Function.DATETIME;
  }

  public String getCN()
  {
    return "DATEINYEAR(date, number):函数返回在一年当中第几天的日期。\n示例：\nDATEINYEAR(2008,100)等于2008-04-09，等价于DATEINYEAR(\"2008-08-08\",100)，也返回2008-04-09.\nDATEINYEAR(2008,-1)等于2008-12-31，等价于DATEINYEAR(\"2008-08-08\",-1)，也返回2008-12-31.";
  }

  public String getEN()
  {
    return "DATEINYEAR(date, number):return the date of one day in a year.\nExample：\nDATEINYEAR(2008,100)=2008-04-09，equals to DATEINYEAR(\"2008-08-08\",100)=2008-04-09.\nDATEINYEAR(2008,-1)=2008-12-31,equals to DATEINYEAR(\"2008-08-08\",-1)=2008-12-31.";
  }
}